﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CUREBusinessLogicLayer;

namespace CURE.Handler
{
    public class AuthorityHandler : IHttpHandler
    {
        AuthorityBll authoritybll = new AuthorityBll();
        EventLogBll eventlogbll = new EventLogBll();
        public void ProcessRequest(HttpContext context)
        {
            string action = context.Request["action"];
            string info = context.Request["info"];//用户组名称
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add("info", info);
            dic.Add("strRights", context.Request.Form["c1"]);
            string masterid = string.Empty;//当前登录用户
            if (HttpContext.Current.Request.Cookies["MWS_User"] != null)
            {
                masterid = HttpContext.Current.Request.Cookies["MWS_User"]["ID"];
            }
            if (action != "" && action != null)
            {
                if (action == "edit")
                {
                    if (authoritybll.EditGroupAuthority(dic))
                    {
                        context.Response.Write(success());
                        Dictionary<string, object> eventlogdic = new Dictionary<string, object>();
                        eventlogdic.Add("masterid", masterid);
                        eventlogdic.Add("msg", "修改权限：" + authoritybll.GetGroupNameByInfo(info) + "");
                        eventlogbll.InsertEventLog(eventlogdic);
                    }
                    else
                    {
                        context.Response.Write(failure());
                    }

                }
            }
        }

        #region 提示信息
        /// <summary>
        /// 操作失败(无参数)
        /// </summary>
        /// <returns></returns>
        public string failure()
        {
            return "{\"statusCode\":\"300\", \"message\":\"操作失败\"}";
        }
        /// <summary>
        /// 操作失败(有参数)
        /// </summary>
        /// <param name="str">错误提示</param>
        /// <returns></returns>
        public string failure(string str)
        {
            return "{\"statusCode\":\"300\", \"message\":\"操作失败!" + str + "\"}";
        }
        /// <summary>
        /// 操作成功(无参数)
        /// </summary>
        /// <returns></returns>
        public string success()
        {
            return "{\"statusCode\":\"200\", \"message\":\"操作成功!\",\"callbackType\":\"closeCurrent\"}";
        }

        public string success1()
        {
            return "{\"statusCode\":\"200\", \"message\":\"操作成功!\"}";
        }

        /// <summary>
        /// 操作成功(有参数)
        /// </summary>
        /// <param name="str">信息</param>
        /// <param name="navTabId">页面指向</param>
        /// <returns></returns>
        public string success(string str, string navTabId)
        {
            return "{\"statusCode\":\"200\", \"message\":\"操作成功!" + str + "\",\"navTabId\":\"" + navTabId + "\"}";
        }
        public string success(string navTabId)
        {
            return "{\"statusCode\":\"200\", \"message\":\"操作成功!\",\"callbackType\":\"closeCurrent\",\"navTabId\":\"" + navTabId + "\"}";
        }
        #endregion
        public bool IsReusable
        {
            get { throw new NotImplementedException(); }
        }


    }
}